import React, { Component } from 'react'
import axios from 'axios'
import NewItemList from './NewItemList'
import Header from '../Header'
import Footer from '../Footer'
import './search.scss'

class Search extends Component {
  state = {
    list: [],
    keyword: '',
  }

  componentDidMount() {
    // console.log(this.props.location.search);
    let str =
      this.props.location.search || '?__timestamp=1598528836839&keyword=推荐'
    axios
      .get(
        '/xhr/search/search.json' +
          str +
          '&sortType=0&descSorted=false&categoryId=0&matchType=0&floorPrice=-1&upperPrice=-1&size=40&itemId=0&stillSearch=false&searchWordSource=1&needPopWindow=true&_stat_search=userhand'
      )
      .then((res) => {
        var keyword = res.data.data.directOrginQuery
        var list = res.data.data.directlyList || []
        this.setState({
          list,
          keyword,
        })
      })
  }
  render() {
    const { list, keyword } = this.state
    if (keyword) {
      return (
        <div className="searchWarp">
          <div className="searchTop">
            <Header></Header>
          </div>
          <NewItemList list={list} keyword={keyword}></NewItemList>
          <div className="searchBot">
          <Footer></Footer>
          </div>
        </div>
      )
    } else {
      return <div>加载中...</div>
    }
  }
  /* render结束 */
}

export default Search
